package com.forg.dubbox.example.provider.service.impl;


import com.forg.dubbox.example.client.dto.EnumSerializDTO;
import com.forg.dubbox.example.client.service.IExampleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.UUID;

/**
 * Created by forgkan on 15.11.9.
 */
@Component("normalProviderServiceImpl")
public class NormalProviderServiceImpl implements IExampleService {

    private static final Logger logger = LoggerFactory.getLogger(NormalProviderServiceImpl.class);

    @Override
    public EnumSerializDTO getEnumDTO(String msg) {

        if(msg == null || msg.trim().length() == 0){
            msg = "forgkan give a message";
        }

        EnumSerializDTO dto = EnumSerializDTO.SUCCESS;
        dto.setMsg(msg);
        return dto;
    }

    @Override
    public String getStr(Integer n) {

        logger.info("invoke getStr paramter n = {}" ,n);
        StringBuffer sb = new StringBuffer();

        for (int i = 0; i<n; i++){
            sb.append(UUID.randomUUID());
        }

        logger.info("invoke getStr return size = {}" ,sb.length());
        return sb.toString();
    }

    @Override
    public String getStr(String n) {

        if(StringUtils.isEmpty(n)){
            n = "10" ;
        }

        return getStr(Integer.valueOf(n));

    }
}
